/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mrs.database;

import java.sql.*;
import java.util.*;

/**
 *
 * @author pablo
 */

public class DB {

  private static final String JDBC_DRIVER = "org.sqlite.JDBC";
  private static final String CONNECTION_STRING = "jdbc:sqlite:data/db/menus.sqlite";
  
  private static Connection con;
  
  public static Connection connect() throws Exception
  {
      Class.forName(JDBC_DRIVER);
      DB.con = DriverManager.getConnection(CONNECTION_STRING);
      return con;
  }
  
  public static void disconnect() throws SQLException
  {
      DB.con.close();
  }
  
  public static ArrayList<ResultSet> getAllResultsets(String table) throws Exception {

      ArrayList elements = new ArrayList();
      Statement stat = connect().createStatement();
      ResultSet rs = stat.executeQuery("select * from " + table + ";");

      while (rs.next()) {
        elements.add(rs);
      }
      rs.close();
      DB.disconnect();
      return (elements);
  }
}
